export default {
  namespaced: true,
  state: {
    list: [],
  },
  mutations: {
    /* 添加商品到购物车 */
    addList(state, obj) {
      state.list.push(obj);
    },
    /* 商品数量增加 */
    changeNum(state, obj) {
      state.list[obj.index].count += obj.number;
    },
    //商品数量减少
    changeCum(state, obj) {
      state.list[obj.index].count -= obj.number;
    },
    /* 删除商品 */
    delCart(state, index) {
      state.list.splice(index, 1);
    },
  },
  getters: {
    /* 购物车中总的数量 */
    cartNum(state) {
      var sum = 0;
      state.list.forEach((item) => {
        sum += item.count;
      });
      return sum;
    },
  },
};
